package Demo1;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-06-05
 * Time: 15:39
 */
public class Test {
    public static void main(String[] args) {

    }
//    var name = "hello";//var不能用来声明字段
//    var name(var i){//var不能用来声明方法的放回值和参数
//
//    }
    public static void func(String name){
        System.out.println(name);
    }
    public static void main5(String[] args) {
//        var name;//error
//        var name = null;//error  var用来初始化变量必须初始化，并且不能赋值为null
        var name = "hello";
        func(name);
    }
    public static void main4(String[] args) {
        Scanner scanner  = new Scanner(System.in);
        System.out.println("请输入一个数字:");
        int ret = scanner.nextInt();
        String str = switch(ret){
            case 1: yield "结果为1";
            case 2: yield "结果为2";
            case 3: yield "结果为3";
            default : yield "结果为4";
        };
        System.out.println(str);
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个数字:");
        int ret = scanner.nextInt() / 10;
        String result = switch(ret){
            case 1 -> "结果为1";
            case 2 -> "结果为2";
            case 3 -> "结果为3";
            default -> "结果为4";
        };
        System.out.println(result);
    }
    public static void main2(String[] args) {
        String data = "one";
        int val = switch(data){
            case "one" -> 1;
            case "two" -> 2;
            case "three" -> 3;
            default -> 4;
        };
        System.out.println("val = " + val);
    }
    public static void main1(String[] args) {
        String data = "one";
        int date = 0;//设置一个初始值
        switch (data){
            case "one":
                date = 1;//重新对date进行赋值
                break;
            case "two":
                date = 2;
                break;
            case "three":
                date = 3;
                break;
            default:
                date = 4;
                break;
        }
        System.out.println("date = " + date);
    }
}
